/**
 * 用户管理页面js
 * 版权所有：上海戈品投资管理有限公司
 *   author king
     功能说明：用户管理
     创建日期：2015-10-15
     修改记录：
     备注说明：
 */

$(document).ready(function() {
	showCourierApplyList();
	courierCompany();
});


/**
 * 用户列表
 * @returns
 */
var showCourierApplyList = function(){
	/*var agentId = $('#agentId').val(); //代理人编号
	var agentName = $('#agentName').val(); //代理人名称
	var userName=$("#userName").val();
	var userId=$("#userId").val();
	var toBlackType=$("#isBlackType").val();
	var userType=$("#userType").val();//用户类型
	var courRealName=$("#courRealName").val();
	var courTel=$("#courTel").val();
	var createTime = $("#createTime").val();//关注时间
	var userStatus=$("#userStatus").val();//用户状态
	var cancelFocusTime=$("#cancelFocusTime").val();//取关时间
*/	
	var datas=getParams();
	//var datas =  {"p":"seachAgentDevelopUsers","m":"query","agentId":agentId,"agentName":agentName,"userName":userName,"userId":userId,"toBlackType":toBlackType,"userType":userType,"courRealName":courRealName,"courTel":courTel,"createTime":createTime,"userStatus":userStatus,"cancelFocusTime":cancelFocusTime};
	var columnDefine = {"id":"用户ID","name":"用户昵称","phone":"手机","registTime":"关注时间","agentId":"代理人编号","agentName":"代理人名称","isBlack":"是否拉黑"};
	
	var formatters={
				"tjType": function (column, rowData)
	            {
					var tjType=rowData.tjType;
    				if(tjType==0){
    					return "无推荐人";
    				}else if(tjType==1){
    					return "快递员推荐";
    				}else if(tjType==2){
    					return "内部推荐";
    				}else if(tjType==3){
    					return "内部测试";
    				}else if(tjType==4){
    					return "系统推荐";
    				}
	            },
	            "rollStatus": function (column, rowData)
	            {
	            	if(rowData.rollStatus==3){
    					return "已拉黑";
    				}
    				return "";
	            },
	            "isAccept": function (column, rowData)
	            {
	            	if(rowData.isAccept==1){
    					return "是";
    				}else{
    					return "否";
    				}
	            },
	            "status": function (column, rowData)
	            {
	            	var status=rowData.status;
				    var sText;
				    if(status=="1"){
				    	sText="审核通过";
				    }else if(status=="0"){
				    	sText='<a style="color:#0066FF" href="javascript:void(0)" onclick="courierAudit(this,1,\''+rowData.id+'\')">通过</a>'+
				    		'&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" onclick="courierAudit(this,2,\''+rowData.id+'\')" style="color:#0066FF">不通过</a>';
				    }else{
				    	sText="审核未通过";
				    }
					return sText;
	            },
	            "checkCourierTime": function (column, rowData)
	            {
	            
	            	if(rowData.checkCourierTime!=0){
    					return timeFormatTrans(rowData.checkCourierTime*1000);
    				}
    				return "";
	            },
	            "applyTime": function (column, rowData)
	            {
	            	
	            	if(rowData.applyTime!=0){
    					return timeFormatTrans(rowData.applyTime*1000);
    				}
    				return "";
	            },
	            "hotline": function (column, rowData)
	            {
	            	return '<a class="add-area" onclick="showAreaEditWin('+rowData.id+');">片区</a>';
	            },
	            "type": function (column, rowData)
	            {
	            	if(rowData.type==1){
						 return "普通快递员";
					 }else if(rowData.type==3){
						 return "<a onMouseOver='showImg("+rowData.id+")'>站长</a><input type='hidden' id='"+rowData.id+"' value='"+rowData.payQrCode+"'/>";            					
					 }else if(rowData.type==2){
						 return "送件快递员";
					 };
	            },
	            "site_number": function (column, rowData)
	            {
	            	if(rowData.site_number==0){
	            		return "";
					}else{
						return rowData.site_number;
					}
	            },
	            "remark": function (column, rowData)
	            {
	            	return '<span  title="'+rowData.remark+'">'+rowData.remark+'</span>';
	            }
	 };
		var buttons =''; //操作按钮
		buttons+='<p>';
		buttons+='<button type=\'button\' class=\'btn btn-w-m btn-danger\' onclick="showSetupGroupWin();">设置分组</button>&nbsp;&nbsp;';
		buttons+='<button type=\'button\' class=\'btn btn-w-m btn-info\' onclick="hidePwin(\'pop_win\');courierOperate(2);">修改快递员信息</button>';
		buttons+='</p>';
		
	   hui.pager('service',datas ,"dataList", columnDefine , formatters , buttons ); //分页查询
	   courierCompany("courierCompany",1);
	
};

var getParams=function(){
	var auditStatus=$("#auditStatusList").val();//审核状态
	var referrerType=$("#referrerList").val();//推荐人类别
	var referrer=$("#referrer").val();//推荐人
	var redPackStatus=$("#redPackStatusList").val();//红包状态
	var courID=$("#courID").val();//快递员id
	var courTel=$("#courTel").val();//快递员手机号
	var courName=$("#courName").val();//快递员姓名
	var isAccept=$("#isAccept").val();//接单状态
	//var isBlackType=$("#isBlackType").val();//拉黑状态
	var auditTime=$("#auditTime").val();//审核时间
	var courierCompany=$("#courierCompany").val();//快递公司
	var registerTime=$("#registerTime").val();
	var courNickName=$("#courNickName").val();
	var remark=$("#remark").val();
	var datas='{"p":"courierAuditList","m":"query"';
	if(auditStatus!=100 && checkParam(auditStatus)){
		datas+=',"status":"'+auditStatus+'"';
	}
	if(referrerType!=100 && checkParam(referrerType)){
		datas+=',"tjType":"'+referrerType+'"';
	}
	if(referrer!="" && checkParam(referrer)){
		datas+=',"tjrName":"'+referrer+'"';
	}
	if(redPackStatus!=100 && checkParam(redPackStatus)){
		datas+=',"rStatus":"'+redPackStatus+'"';
	}
	if(checkParam(isAccept)){
		datas+=',"isAccept":"'+isAccept+'"';
	}
	if(checkParam(courierCompany)){
		datas+=',"courierCompany":"'+courierCompany+'"';
	}
	if(checkParam(courID)){
		datas+=',"courID":"'+courID+'"';
	}
	if(checkParam(courTel)){
		datas+=',"courTel":"'+courTel+'"';
	}
	if(checkParam(courName)){
		datas+=',"courName":"'+courName+'"';

	}
	if(checkParam(courNickName)){
		datas+=',"courNickName":"'+courNickName+'"';
	}
//	if(isBlackType!="" && isBlackType!=null&& isBlackType!='100'){
//		datas+="isBlackType="+isBlackType+"&";
//	}
	if(checkParam(auditTime)){
		datas+=',"auditTime":"'+auditTime+'"';
	}
	if(checkParam(registerTime)){
		datas+=',"registerTime":"'+registerTime+'"';
	}
	if(checkParam(remark)){
		datas+=',"remark":"'+remark+'"';
	}
	datas+='}';
	return eval("("+datas+")");
}
var checkParam=function(param){
	if(param=="" || param==null || param==undefined){
		return false;
	}
	return true;
};

var getTheSureTime=function(emp){
	return emp>9?emp:"0"+emp;
};
//时间格式转换
var timeFormatTrans=function(time){
	var newTime= new Date(time);
	var rowText=newTime.getFullYear()+'-'+getTheSureTime((newTime.getMonth()+1))+'-'
	+getTheSureTime(newTime.getDate())+' '+getTheSureTime(newTime.getHours())+':'
	+getTheSureTime(newTime.getMinutes())+':'+getTheSureTime(newTime.getSeconds());
	return rowText;
};
/*
function courierCompany(){
	var datas={"p":"courierAuditList","m":"queryCompany"};
	var rjson=common.ajaxRequest("service", datas, "post");
	if(rjson && rjson.result == 0){
		var rstr=rjson.companyList;
		var html="<option value=''>==选择快递公司==</option>";
		for(var i=0;i<rstr.length;i++){
			html+="<option value='"+rstr[i].id+"'>"+rstr[i].name+"</option>";
		}
		$("#courierCompany").html(html);
	}
}
*/
/**
 * 功能说明：导出数据
 * @returns
 */
var exportDatas=function(){
	
	var datas=getParams();
	datas["exportData"]=1;
	//alert(JSON.stringify(datas));
	var dataUrl="";
	var rjson=common.ajaxRequest("service", datas, "POST");
	if(rjson && rjson.result == 0){
		if(rjson.exportDataSql){
			dataUrl=rjson.exportDataSql;
		}else{
			common.showMsg('info', '', '导出数据未成功，请刷新重试!');
		}
	}else{
		common.showMsg('info', '', '导出数据操作失败');
	}
	if(!common.validVar(dataUrl)){
		return;		
	}
	var data = {"p":"exportData","sql":dataUrl,"m":""};
	var json = common.ajaxRequest('service', data , 'POST');
	common.showMsg('info', '', json.message);
	window.open(json.excelFile);
};
/**
 * 打开设置窗口
 * @returns
 */
var showSetupWin = function(){
	
	$('#setupWin').modal('show');
};

var showWin=function(winId,methodName){
	$('#'+winId).modal("show");
};
var hidePwin=function(winId){
	$('#'+winId).modal("hide");
};
/**
* 审核完成后进行的审核操作
* @param emp 1：通过，2：不通过
*/
var shenheOperate=function(emp){
	var checks=$('input[name="select"]:checked');
	
	if( checks.length > 0 )
	{
		var id=checks.eq(0).val();
		var ids = '';//选择的checkbox的值，多个用“，”分割
		$(checks).each(function(index,data){
			ids+= $(this).val()+',';
		});
		ids = ids.substring(0, ids.lastIndexOf(','));
		
		var rs=0;
		if(emp==1){//通过
			//rs=courierAudit("",1,id);
			rs=courierAuditBatch("",1,ids);
			if(rs==1)
			{
				//checks.eq(0).parent().nextAll().eq(8).html("审核通过");
				
			}
		}else{//不通过
			//rs=courierAudit("",2,id);
			rs=courierAuditBatch("",2,ids);
			if(rs==1)
			{
				//checks.eq(0).parent().nextAll().eq(8).html("审核不通过");
			}
		}
	}else{
		common.showMsg('info', '', '请选择至少一条记录！');
	}
};
/**
 * 快递员审核 ( 批量 )
 * @param currentDom
 * @param emp 1审核通过  2审核不通过
 * @param courierIds 多选快递员id，用","分割
 * @returns
 */
var courierAuditBatch = function( currentDom , emp , courierIds ){
	var datas={"audit":emp,"userIds":courierIds};
	var datas={"p":"courierAuditOperate","m":"auditBatch","audit":emp,"userIds":courierIds};
	var rjson=common.ajaxRequest('service', datas, "POST");
	if(rjson.result=="0")
	{
		common.showMsg('info', '', rjson.message);
		showCourierApplyList();
		return 1;
	 }
	 else
	 {
		common.showMsg('info', '', "操作失败!");
		return 0;
	}
};
/**
 * 微信消息跳转页面
 * @returns
 */
var wxMsgContent = function(){
	window.location.href='page?p=page/wxMsgContent';
}; 
/**
 * 内部推荐码入口
 * @returns
 */
var showCmManage = function(){
	window.location.href='page?p=page/cmManage';
};

/**
 * 显示设置分组窗口
 * @returns
 */
var showSetupGroupWin = function(){
	
	var data = $('#pop_win .data').text();
	var m = eval('('+data+')');

	var json = common.ajaxRequest('service', {"p":"groupManage","m":"findUserGroupList","userId":m.id}, 'POST');
	var html='';
	if( json && json.groupProjectList )
	{
		$( json.groupProjectList).each(function(){
			if( this.flag > 0 )
			{
				html+='<input  type="checkbox" name="type0" value="'+this.id+'" checked="checked" sname="'+this.name+'" >&nbsp;'+this.name+'<br>';
			}
			else
			{
				html+='<input type="checkbox" name="type0" value="'+this.id+'" sname="'+this.name+'" >&nbsp;'+this.name+'<br>';
			}	
		});
	}
	$('#editUserGroupPop .userId').val(m.id);
	$('#editUserGroupPop .openId').val(m.openID);
	$('#editUserGroupPop .userName').val(m.realName);
	$('#editUserGroupPop .selectList').empty();
	$('#editUserGroupPop .selectList').html(html);
	$('#pop_win').modal('hide');
	$('#editUserGroupPop').modal('show');
	
	$('input[name="type0"]').click(function(){
		
		var cc = this;
		var sname0 = $(cc).attr('sname');
		if( $(cc).is(':checked') )
		{
			$('input[name="type0"]').each(function(){
				if($(this).attr('sname')!=sname0)
				{
					$(this).removeAttr('checked');
				}	
			});
			
		}	
	});

};

/**
 * 设置分组
 * @returns
 */
var setupGroup = function(){
	var userId = $('#editUserGroupPop .userId').val();
	var userOpenId = $('#editUserGroupPop .openId').val();
	var userName = $('#editUserGroupPop .userName').val();
	var groupId;
	var groupName;
	
	$('input[name="type0"]:checked').each(function(){
		groupId = $(this).val();
		groupName = $(this).attr('sname');
	});
	
	var datas = {"p":"groupManage","m":"addGroupUser","userId":userId,"userOpenId":userOpenId,"userName":userName,"groupId":groupId,"groupName":groupName};
	var json = common.ajaxRequest('service', datas , 'POST');
	if( json && json.result == 0 )
	{
		$('#editUserGroupPop').modal('hide');
		common.showMsg('info', '' , '设置分组成功');
	}
	else
	{
		common.showMsg('error', '' , '设置分组失败');
		return;
	}	
};

var cancelCourierWin=function(){
	if(!checkIsOne()){
	   return;
	}
	var userName=$('#dataList input[name="select"]:checked').eq(0).parent().next().next().html();
	$("#winOfSureText").html("确定要取消：【 "+userName+" 】的快递员身份吗");
	showWin('showWinOfSure');
	var userId=$('#dataList input[name="select"]:checked').eq(0).val();
	$("#winOfSure").attr("onclick","cancelCourier('"+userId+"')");
};
var cancelCourier=function(param){
	if(!checkIsOne()){
    	return;
    }
	var userId=$('#dataList input[name="select"]:checked').eq(0).val();
	//下面需要判断是否为空
	if(userId==""){
		common.showMsg('info', '', "操作有误，请刷新页面重试！");
		return;
	}
	var datas={"p":"courierAuditOperate","m":"cancelCourier","userId":userId};
	var rjson=common.ajaxRequest('service', datas, "POST");
	if(rjson && rjson.result == 0){
		if(rjson.cancelResult==0){
			common.showMsg('info', '', "快递员身份已经取消成功！");
			window.location.reload(); 
			//$('input[name="checkCour"]:checked').eq(0).parent().parent().remove();
		}else{
			common.showMsg('info', '', "取消未成功！");
		}
	}else{
		common.showMsg('info', '', "取消快递员身份操作失败！");
	}
};

/**
 * 选择一条记录
 * @returns
 */
var checkIsOne=function(){
	var checks=$('#dataList input[name="select"]:checked');
	if(checks.length!=0 && checks.length<2)
	{
		return true;
	}else{
		common.showMsg('info', '', "请选择一条记录！");
		return false;
	}
};
var courierOperate=function(emp){
	if(emp==1){
		$("#addOrEidtCourier .cEdit").hide();
		$("#addOrEidtCourier .modal-footer button").eq(0).html("新建").attr("onclick","addNewCourier()");
		$("#addOrEidtCourier #myModalLabel").html("新建快递员");
		$("#addOrEidtCourier input[name='siteId']").attr("onkeyup","initCourierSite(this,1)");
		courierCompany("addOrEidtCourier select[name='company']",1);
		courierAddInit("addOrEidtCourier");
		//addNewCourier();
	}else{
		$("#addOrEidtCourier .cEdit").show();
		$("#addOrEidtCourier .modal-footer button").eq(0).html("保存").attr("onclick","modifyCourier('addOrEidtCourier')");
		$("#addOrEidtCourier #myModalLabel").html("编辑快递员");
		$("#addOrEidtCourier input[name='siteId']").attr("onkeyup","initCourierSite(this,2)");
		courierEditInit("addOrEidtCourier");
	}
	showWin("addOrEidtCourier");
};
/**
 * 校验
 * @param type  1 添加校验 2 修改校验
 * @returns
 */
var validateCourierForm = function(type){
	
	var id ="addOrEidtCourier";
	var name = $('#'+id+' input[name="name"]').val();
	var telephone = $('#'+id+' input[name="telephone"]').val();
	var hotline = $('#'+id+' input[name="userHotline"]').val();
	
	if( '' == name || undefined == name )
	{
		common.showMsg('info', '', "姓名不能为空！");
		return false;
	}	
	if( '' == telephone || undefined == telephone )
	{
		
		common.showMsg('info', '', "手机不能为空！");
		return false;
	}	
	if( '' == hotline || undefined == hotline )
	{
		common.showMsg('info', '', "热线不能为空！");
		return false;
	}	
	return true;
};
var selectHotLine = function( obj,id ){
	var value = $(obj).find("option:selected").attr('hotline');
	$('#'+id +" input[name='hotline']").val(value);
};
/*
 * 添加快递员
 */
var addNewCourier=function(){
	var name = $('#addOrEidtCourier input[name="name"]').val();
	var telephone = $('#addOrEidtCourier input[name="telephone"]').val();
	var company = $('#addOrEidtCourier select[name="company"]').val();
	var hotline = $('#addOrEidtCourier input[name="userHotline"]').val();
	var remark = $('#addOrEidtCourier input[name="remark"]').val();
	var siteId = $('#addOrEidtCourier input[name="siteId"]').val();
	var status = $('#addOrEidtCourier select[name="status"]').val();
	var isAccept = $('#addOrEidtCourier select[name="isAccept"]').val();
	var tjType = $('#addOrEidtCourier select[name="tjType"]').val();
	var type = $('#addOrEidtCourier select[name="type"]').val();
	//alert(name+":"+telephone+":"+company+":"+remark+":"+siteId+":"+status+":"+isAccept+":"+tjType+":"+type);
	if( !validateCourierForm(1) )
	{
		return;
	}	
	var datas = {"p":"courierAuditList","m":"addCourier","name":name,"telephone":telephone,"company":company,"hotline":hotline,"remark":remark,"siteId":siteId,"status":status,"isAccept":isAccept,"tjType":tjType,"type":type};
	var json = common.ajaxRequest('service', datas, "POST");
	
	if( json && json.result == 0 )
	{
		common.showMsg('info', '', "创建成功！");
		showCourierApplyList();
		$('#courierNewWin').puidialog('hide'); 
	}
	else
	{
		common.showMsg('info', '', "创建失败,"+json.message);
	}	
};
/**
 * 修改快递员
 * @returns
 */
var modifyCourier = function(obj){
	//alert(obj);
	var id =$("#"+obj+" input[name='courierId']").val();
	var name = $("#"+obj+"  input[name='name']").val();
	var telephone = $("#"+obj+" input[name='telephone']").val();
	var company = $("#"+obj+" select[name='company']") .val();
	var hotline = $("#"+obj+" input[name='userHotline']").val();
	//alert(hotline);
	var remark = $("#"+obj+" input[name='remark']").val();
	var siteId = $("#"+obj+" input[name='siteId']").val();
	var status = $("#"+obj+" select[name='status']").val();
	var isAccept = $("#"+obj+" select[name='isAccept']").val();
	var tjType = $("#"+obj+" select[name='tjType']").val();
	var type = $("#"+obj+" select[name='type']").val();
	if( !validateCourierForm(2) )
	{
		return;
	}	
	var datas = {"p":"courierAuditList","m":"modifyCourier","id":id,"name":name,"telephone":telephone,"company":company,"hotline":hotline,"remark":remark,"siteId":siteId,"status":status,"isAccept":isAccept,"tjType":tjType,"type":type};
	//alert(JSON.stringify(datas));
	var json = common.ajaxRequest('service', datas, "POST");
	
	
	
	if( json && json.result == 0 )
	{
		common.showMsg('info', '', "修改成功！");
		showCourierApplyList();
	}
	else
	{
		common.showMsg('info', '', "修改失败！");
	}	
};

/**
 * 初始化站点列表（添加或者修改快递员时触发）
 * @param q
 * @returns
 */
var initCourierSite = function( obj , type ){
	
	var id ="#addOrEidtCourier";
	var q=$(obj).val();
	if( null!= q && q!='' )
	{
		var datas={"p":"siteManage","m":"list","name":q};
		var json=common.ajaxRequest('service', datas, "GET");
		//var json = common.ajaxRequest('/wx/ajax?p=siteManage&m=list&name=' +q, null, 'GET');
		if( json && json.result == 0 )
		{
			id=id+" .zhandian";
			if( json.courierList && json.courierList.length > 0 )
			{
				
				$(id).empty();
				var str1='<li><a href="javascript:chooseSite(';
				$(json.courierList).each(function(){
					$(id).append('<li><a href="javascript:chooseSite(\''+this.id+'\',\''+id+'\')">' + this.name +'</a></li>');
				});
			}	
			else
			{
				$(id).empty();
			}
			$(id).prev().attr("aria-expanded","true").parent().removeClass("open").addClass("open");
		}
		else
		{
			window.parent.pui.cmNotify( json.message);
		}	
	}
};
/*
 * 站点选择触发事件
 */
var chooseSite=function(uid,obj){
	$(obj).prev().val(uid);
};

/*
 * 编辑修改快递员
 */
//showWin('editCourierInfo');
var courierEditInit=function(obj){
	
	//courierCompany("addOrEidtCourier select[name='company']",1);
	var data=$("#pop_win .data").html();
	var datas=eval('('+data+')');
	$("#"+obj+" input[name='courierId']").val(datas.id);
	$("#"+obj+" input[name='name']").val(datas.name);
	$("#"+obj+" input[name='telephone']").val(datas.telephone);
	selectCheck(obj+" select[name='status']",datas.status,1);
	selectCheck(obj+" select[name='tjType']",datas.tjType,1);
	selectCheck(obj+" select[name='isAccept']",datas.isAccept,1);
	selectCheck(obj+" select[name='type']",datas.type,1);
	courierCompany(obj+" select[name='company']",2,datas.company);
	$("#"+obj+" input[name='userHotline']").val(datas.hotline);
	$("#"+obj+" input[name='siteId']").val(datas.siteId);
	$("#"+obj+" input[name='registTime']").val(timeFormatTrans(datas.registTime));
	$("#"+obj+" input[name='checkCourierTime']").val(timeFormatTrans(datas.checkCourierTime*1000));
	$("#"+obj+" input[name='remark']").val(datas.remark);
	
};
/*
 * 新建快递员
 */
//showWin('editCourierInfo');
var courierAddInit=function(obj){
	
	//courierCompany("addOrEidtCourier select[name='company']",1);
	$("#"+obj+" input[name='name']").val("");
	$("#"+obj+" input[name='telephone']").val("");
	//selectCheck(obj+" select[name='status']",datas.status,1);
	//selectCheck(obj+" select[name='tjType']",datas.tjType,1);
	//selectCheck(obj+" select[name='isAccept']",datas.isAccept,1);
	//selectCheck(obj+" select[name='type']",datas.type,1);
	courierCompany(obj+" select[name='company']",2,"");
	
	$("#"+obj+" input[name='hotline']").val("");
	$("#"+obj+" input[name='siteId']").val("");
	$("#"+obj+" input[name='registTime']").val("");
	$("#"+obj+" input[name='checkCourierTime']").val("");
	$("#"+obj+" input[name='userHotline']").val("");
	$("#"+obj+" input[name='remark']").val("");
	
};
var selectCheck=function(obj,param,type){
	var options=$("#"+obj+" option");
	for(var i=0;i<options.length;i++){
		if(type==1){
			if(options.eq(i).attr("value")!=param){
				continue;
			};
		}else if(type==2){
			if(options.eq(i).html()!=param){
				continue;
			};
		}
		options.eq(i).attr("selected","selected");
	}
};
var courierCompany=function(obj,type,companyName){
	var datas={"p":"courierAuditList","m":"queryCompany"};
	var rjson=common.ajaxRequest("service", datas, "post");
	if(rjson && rjson.result == 0){
		var rstr=rjson.companyList;
		var html='';
		if(type==1){
			for(var i=0;i<rstr.length;i++){
				if(companyName && companyName==rstr[i].name){
					html="<option value='"+rstr[i].id+"'>"+rstr[i].name+"</option>"+html;
				}else{
					html+="<option value='"+rstr[i].id+"'>"+rstr[i].name+"</option>";
				}
			}
			if(!companyName){
				html="<option value=''>==选择快递公司==</option>"+html;
			}
		}else if(type==2){
			for(var i=0;i<rstr.length;i++){
				if(companyName && companyName==rstr[i].name){
					html="<option hotline='"+rstr[i].hotline+"' value='"+rstr[i].name+"'>"+rstr[i].name+"</option>"+html;
				}else{
					html+="<option hotline='"+rstr[i].hotline+"' value='"+rstr[i].name+"'>"+rstr[i].name+"</option>";
				}
				
			}
		}
		$("#"+obj).html(html);
		
	}
};
var selectHotLine = function( obj,id ){
	
	var value = $(obj).find("option:selected").attr('hotline');
	$('#'+id).val(value);
};

